package com.bzyd.cloud.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * 测试RocketMQ监听器
 * Created by Xianyue Dang on 2021/8/20
 */
@Slf4j
@Service
@RocketMQMessageListener(consumerGroup = "test-topic-listener", topic = "test-topic-1")
public class TestTopicListener implements RocketMQListener<String> {


    @Override
    public void onMessage(String message) {
        log.info("测试RocketMQ监听器接收到消息：{}", message);
        if ("error".equals(message)){
            throw new RuntimeException("模拟错误");//测试消费异常时会重复投递
        }
    }
}
